--*****************************************************************************
--*     DB Creation Script :: ExceptionContexts Table
--*     Copyright (C) 2003, Perot Systems Corporation. All right reserved.
--*****************************************************************************
--* Developer: Dmitry Frenkel

 
--*****************************************************************************
--* Step 1. Create Table
--*****************************************************************************
SET NOCOUNT OFF

PRINT 'Creating Table ExceptionContexts...'
GO

IF OBJECT_ID( 'ExceptionLog' ) IS NOT NULL AND OBJECT_ID ('ExceptionContexts') IS NULL
BEGIN
	CREATE TABLE [DBO].ExceptionContexts
	(
		[OID] BIGINT IDENTITY( 1,1 ) NOT NULL,
		[ExceptionID] BIGINT NOT NULL,
		[Key] VARCHAR(64) NOT NULL,
		[Value] VARCHAR(1024) NULL,
		timestamp ROWVERSION,
		CONSTRAINT [PK_ExceptionContexts] PRIMARY KEY CLUSTERED( [OID] ) ON [PRIMARY],
		CONSTRAINT [FK_ExceptionContexts_ExceptionLog] 
				FOREIGN KEY( [ExceptionID] )
				REFERENCES [DBO].[ExceptionLog]( [OID] ),
		CONSTRAINT [UIX_ExceptionContexts] UNIQUE( [ExceptionID], [Key] )
	)
    PRINT 'Table ExceptionContexts has been created successfully.'
END
ELSE BEGIN
    PRINT 'Table ExceptionContexts already exists.'
END
GO

--******************************************************************************
--* Step 2. Permissions
--******************************************************************************   